package com.maimang.platform.common.entity;

import com.maimang.platform.annotation.Excel;
import com.maimang.platform.base.BaseEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author Rocky
 */
public class SysUser extends BaseEntity {
	private static final long serialVersionUID = 1L;

	private String key;
	/**
	 * 用户ID
	 */
	@Excel(name = "用户序号")
	private Long userId;
	/**
	 * 部门ID
	 */
	// @Excel(name = "部门编号", type = Excel.Type.IMPORT)
	private Long deptId;
	/**
	 * 员工在当前开发者企业账号范围内的唯一标识
	 */
	// @Excel(name = "员工在当前开发者企业账号范围内的唯一标识")
	private String unionid;
	/**
	 * 员工在当前企业内的唯一标识
	 */
	// @Excel(name = "员工在当前企业内的唯一标识")
	private String userid;
	/**
	 * 第三方openid
	 */
	// @Excel(name = "第三方openid")
	private String openId;
	/**
	 * 在对应的部门中是否为主管
	 */
	@Excel(name = "在对应的部门中是否为主管")
	private String isLeaderInDepts;
	/**
	 * 部门父ID
	 */
	private Long parentId;
	/**
	 * 登录名称
	 */
	@Excel(name = "登录名称")
	private String loginName;
	/**
	 * 用户名称
	 */
	@Excel(name = "用户名称")
	private String userName;
	/**
	 * 用户类型（00系统用户,01）
	 */
	@Excel(name = "用户类型", readConverterExp = "0=系统用户,01=非系统用户")
	private String userType;
	/*
	 * 用户邮箱
	 */
	@Excel(name = "用户邮箱")
	private String email;
	/**
	 * 员工的企业邮箱
	 */
	@Excel(name = "员工的企业邮箱")
	private String orgEmail;
	/**
	 * 手机号码
	 */
	@Excel(name = "手机号码")
	private String phonenumber;
	/**
	 * 用户性别
	 */
	@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
	private String sex;
	/**
	 * 用户头像
	 */
	private String avatar;
	/**
	 * 密码
	 */
	private String password;
	/**
	 * 盐加密
	 */
	private String salt;
	/**
	 * 办公地点
	 */
	@Excel(name = "办公地点")
	private String workPlace;
	/**
	 * 帐号状态（0正常 1停用）
	 */
	@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
	private String status;
	/**
	 * 是否是管理员（0否 1是）
	 */
	@Excel(name = "是否是管理员")
	private String isAdmin;
	/**
	 * 是否老板（0否 1是）
	 */
	@Excel(name = "是否老板")
	private String isBoss;
	/**
	 * 在对应的部门中的排序
	 */
	@Excel(name = "在对应的部门中的排序")
	private String orderInDepts;
	/**
	 * 职位信息
	 */
	@Excel(name = "职位信息")
	private String position;
	/**
	 * 入职时间
	 */
	@Excel(name = "入职时间")
	private Date hiredDate;
	/**
	 * 员工工号
	 */
	@Excel(name = "员工工号")
	private String jobNumber;
	/**
	 * 是否高管（0否 1是）
	 */
	@Excel(name = "是否高管")
	private String isSenior;
	/**
	 * 国家地区码
	 */
	@Excel(name = "国家地区码")
	private String stateCode;
	/**
	 * 预留字段
	 */
	private String tags;
	/*
	 * 删除标志（0代表存在 2代表删除）
	 */
	@Excel(name = "删除标志")
	private String delFlag;
	/**
	 * 最后登录IP
	 */
	@Excel(name = "最后登录IP", type = Excel.Type.EXPORT)
	private String loginIp;
	/**
	 * 最后登录时间
	 */
	@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
	private Date loginDate;
	/**
	 * 下属部门对象
	 */
	private List<SysDeptTree> depts;

	/**
	 * 部门对象
	 */
	@Excel(name = "部门名称", targetAttr = "deptName", type = Excel.Type.EXPORT)
	private List<SysDept> dept;

	private List<SysRole> roles;
	/**
	 * 角色组
	 */
	private Long[] roleIds;
	/**
	 * 岗位组
	 */
	private Long[] postIds;
	/**
	 * 部门组id
	 */
	private Long[] deptIds;

	public SysUser() {

	}

	public static boolean isAdmin(Long userId) {
		return userId != null && 1L == userId;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getUnionid() {
		return unionid;
	}

	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public String getOrgEmail() {
		return orgEmail;
	}

	public void setOrgEmail(String orgEmail) {
		this.orgEmail = orgEmail;
	}

	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public boolean isAdmin() {
		return isAdmin(this.userId);
	}

	public Long getDeptId() {
		return deptId;
	}

	public void setDeptId(Long deptId) {
		this.deptId = deptId;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(String phonenumber) {
		this.phonenumber = phonenumber;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getWorkPlace() {
		return workPlace;
	}

	public void setWorkPlace(String workPlace) {
		this.workPlace = workPlace;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(String isAdmin) {
		this.isAdmin = isAdmin;
	}

	public String getIsBoss() {
		return isBoss;
	}

	public void setIsBoss(String isBoss) {
		this.isBoss = isBoss;
	}

	public String getOrderInDepts() {
		return orderInDepts;
	}

	public void setOrderInDepts(String orderInDepts) {
		this.orderInDepts = orderInDepts;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public Date getHiredDate() {
		return hiredDate;
	}

	public void setHiredDate(Date hiredDate) {
		this.hiredDate = hiredDate;
	}

	public String getJobNumber() {
		return jobNumber;
	}

	public void setJobNumber(String jobNumber) {
		this.jobNumber = jobNumber;
	}

	public String getIsSenior() {
		return isSenior;
	}

	public void setIsSenior(String isSenior) {
		this.isSenior = isSenior;
	}

	public String getStateCode() {
		return stateCode;
	}

	public void setStateCode(String stateCode) {
		this.stateCode = stateCode;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	public Date getLoginDate() {
		return loginDate;
	}

	public void setLoginDate(Date loginDate) {
		this.loginDate = loginDate;
	}

	public List<SysDept> getDept() {
		if (dept == null) {
			dept = new ArrayList<>();
		}
		return dept;
	}

	public void setDept(List<SysDept> dept) {
		this.dept = dept;
	}

	public String getDeptName() {
		String deptName = StringUtils.EMPTY;
		if (dept != null) {
			for (SysDept d : dept) {
				if (StringUtils.isEmpty(deptName))
					deptName = d.getDeptName();
				else
					deptName = deptName + "," + d.getDeptName();
			}
		}
		return deptName;
	}

	public List<SysRole> getRoles() {
		return roles;
	}

	public void setRoles(List<SysRole> roles) {
		this.roles = roles;
	}

	public Long[] getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(Long[] roleIds) {
		this.roleIds = roleIds;
	}

	public List<SysDeptTree> getDepts() {
		if (depts == null) {
			depts = new ArrayList<>();
		}
		return depts;
	}

	public void setDepts(List<SysDeptTree> depts) {
		this.depts = depts;
	}

	public Long[] getDeptIds() {
		return deptIds;
	}

	public void setDeptIds(Long[] deptIds) {
		this.deptIds = deptIds;
	}

	public Long[] getPostIds() {
		return postIds;
	}

	public void setPostIds(Long[] postIds) {
		this.postIds = postIds;
	}

	public String getIsLeaderInDepts() {
		return isLeaderInDepts;
	}

	public void setIsLeaderInDepts(String isLeaderInDepts) {
		this.isLeaderInDepts = isLeaderInDepts;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("userId", getUserId())
				.append("unionid", getUnionid())
				.append("userid", getUserid())
				.append("openId", getOpenId())
				.append("isLeaderInDepts", getIsLeaderInDepts())
				.append("deptId", getDeptId())
				.append("loginName", getLoginName())
				.append("userName", getUserName())
				.append("userType", getUserType())
				.append("email", getEmail())
				.append("orgEmail", getOrgEmail())
				.append("phonenumber", getPhonenumber())
				.append("sex", getSex())
				.append("avatar", getAvatar())
				.append("password", getPassword())
				.append("salt", getSalt())
				.append("workPlace", getWorkPlace())
				.append("status", getStatus())
				.append("isAdmin", getIsAdmin())
				.append("isBoss", getIsBoss())
				.append("orderInDepts", getOrderInDepts())
				.append("position", getPosition())
				.append("hiredDate", getHiredDate())
				.append("jobNumber", getJobNumber())
				.append("isSenior", getIsSenior())
				.append("stateCode", getStateCode())
				.append("tags", getTags())
				.append("delFlag", getDelFlag())
				.append("loginIp", getLoginIp())
				.append("loginDate", getLoginDate())
				.append("createUser", getCreateUser())
				.append("createTime", getCreateTime())
				.append("updateUser", getUpdateUser())
				.append("updateTime", getUpdateTime())
				.append("remark", getRemark())
				.append("dept", getDept())
				.toString();
	}
}
